********************************************************************************
*                                Set Directory                                 *
********************************************************************************
clear all

global user "~\SHEPad"

global output "~\SHEPad\output"
cd "${output}"

* year-interacted controls
global yearinteracted
global controls "total_enrolbg_2013 bookinlib_2013 toiletd_2013 toiletb_2013 toiletg_2013 clrooms_2013 clgood_2013 smc_2013 smcsdp_2013 medchk_2013 electric_2013 library_2013 playground_2013 ramps_2013 cal_2013 access_2013 water_hp_2013 water_well_2013 water_tap_2013 water_others_2013 bld_govt_2013 bld_uc_2013 bld_dilap_2013 wall_pucca_2013 wall_wire_2013 wall_hedges_2013 wall_na_2013"
foreach v in $controls {
  global yearinteracted $yearinteracted c.`v'#i.year
}

* count number of schools
cap prog drop tabschool
program define tabschool, rclass
preserve
keep if e(sample)
duplicates drop schcd, force
tab t_machine_installed
restore
end

********************************************************************************
*                                   Figure 1                                   *
********************************************************************************
use "${user}\data\data.dta", clear

forval i=5/10 {
reghdfe chg_enrolment`i' before6 before5 before4 before3 before2 after0 after1 after2 after3 before1 $yearinteracted if balancedpanel`i'==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
est store Dynamic`i'
coefplot Dynamic`i', omitted keep(before* after*) order(before6 before5 before4 before3 before2  before1 after0 after1 after2 after3) vertical recast(connect) ciopts(recast(rcap) lpattern(dash) lcolor(black%90)) lpattern(solid) mcolor(black) lcolor(black) yline(0,lcolor(gray%50)) xtitle(Treatment Period) ylabel(-1.5(.5)2,angle(90) glcolor(gs15%50)) scale(titlegap(.5) outergap(.5)) graphregion(color(white) margin(2 2 2 2)) plotregion(lcolor(black)) xline(6, lcolor(red%50)) title(`i'th Grade) ytitle(DID Estimates)
graph save "${output}\figure`i'.gph",replace
}
graph combine figure5.gph figure6.gph figure7.gph figure8.gph figure9.gph figure10.gph, row(2) col(3) ysize(10) xsize(20) commonscheme graphregion(color(white)) saving("${output}\figure1.gph", replace)

forval i=5/10 {
erase "${output}\figure`i'.gph"
}

********************************************************************************
*                                   Table 1                                    *
********************************************************************************
use "${user}\data\data.dta", clear

* label variable
label var aft AfterT

reghdfe chg_enrolment5 aft $yearinteracted if balancedpanel5==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table1.doc", replace nocons nonotes label bdec(3) sdec(3) ctitle(5th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, No. of treated schools, 496, No. of control schools, 6095, Pre-treatment average dropouts, -0.183 )
tabschool

reghdfe chg_enrolment6 aft $yearinteracted if balancedpanel6==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table1.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(6th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, No. of treated schools, 504, No. of control schools, 6000, Pre-treatment average dropouts, -0071 )
tabschool

reghdfe chg_enrolment7 aft $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table1.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, No. of treated schools, 494, No. of control schools, 2920, Pre-treatment average dropouts, -0.735 )
tabschool

reghdfe chg_enrolment8 aft $yearinteracted if balancedpanel8==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table1.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(8th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, No. of treated schools, 689, No. of control schools, 3117, Pre-treatment average dropouts, -0.048 )
tabschool

reghdfe chg_enrolment9 aft $yearinteracted if balancedpanel9==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table1.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(9th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, No. of treated schools, 687, No. of control schools, 2947, Pre-treatment average dropouts, -0.054 )
tabschool

reghdfe chg_enrolment10 aft $yearinteracted if balancedpanel10==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table1.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(10th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, No. of treated schools, 640, No. of control schools, 1668, Pre-treatment average dropouts, -1.207 )
tabschool

********************************************************************************
*                                   Table 2                                    *
********************************************************************************
use "${user}\data\data.dta", clear

* Goodman-Bacon's Decomposition (using balanced data)
xtset school_gender year
forval i=5/10 {
preserve
keep if !missing(chg_enrolment`i')
egen mminyear=min(year),by(schcd)
egen mmaxyear=max(year),by(schcd)
gen ccount=1
egen fcount=sum(ccount),by(schcd)
drop if mminyear!=2013 | mmaxyear!=2018 | fcount!=6
bacondecomp chg_enrolment`i' aft, ddetail nograph
matrix w`i' = e(sumdd)
matrix rownames w`i' = 1 2 3 4 5 6 7 8 9 10 11 12 13
matrix colnames w`i' = 1 2
matrix w`i'_1 = w`i'["1", "2"]
matrix w`i'_2 = w`i'["2", "2"]
forval j=3(2)11 {
matrix w`i'_`j' = w`i'["`j'", "2"]
}
forval j=2(2)12 {
matrix w`i'_`j' = w`i'["`j'", "2"]
}
matrix w`i'_el = w`i'_1 + w`i'_3 + w`i'_5 + w`i'_7 + w`i'_9 + w`i'_11
matrix w`i'_le = w`i'_2 + w`i'_4 + w`i'_6 + w`i'_8 + w`i'_10 + w`i'_12
matrix w`i'_tn = w`i'["13", "2"]
matrix w`i' = (w`i'_el \ w`i'_le \ w`i'_tn)
matrix rownames w`i' = "Earlier Treated v Later Control" "Later Treated v Earlier Control" "Treated v Never Treated"
matrix colnames w`i' = "`i'th-Grade"
restore
}
matrix w_all = (w5,w6,w7,w8,w9,w10)
esttab m(w_all, fmt(%5.3f)) using "${output}\Table2a.doc", replace nomti


* de Chaisemartin and d'Haultfoeuille’s Test for Negative Weights
use "${user}\data\data.dta", clear

* year-interacted controls (dummies)
gen yearindicator=year-2012 if !missing(year)
local controls "total_enrolbg_2013 bookinlib_2013 toiletd_2013 toiletb_2013 toiletg_2013 clrooms_2013 clgood_2013 smc_2013 smcsdp_2013 medchk_2013 electric_2013 library_2013 playground_2013 ramps_2013 cal_2013 access_2013 water_hp_2013 water_well_2013 water_tap_2013 water_others_2013 bld_govt_2013 bld_uc_2013 bld_dilap_2013 wall_pucca_2013 wall_wire_2013 wall_hedges_2013 wall_na_2013"
global yicontrols
foreach v in $controls {
forval i=1/6 {
 gen yi_`v'_`i' = `v'*(yearindicator==`i')
 global yicontrols $yicontrols yi_`v'_`i'
}
}
gen t_machine_installation=t_machine_installed==1 & year>=t_machine_year & gender==2

forval i = 5/10 {
twowayfeweights chg_enrolment10 school_gender year t_machine_installation if balancedpanel`i'==1, type(feTR) controls($yicontrols)
matrix tw`i' = e(M)
matrix rownames tw`i' = 1 2 3
matrix colnames tw`i' = 1 2
matrix tw`i'_11 = tw`i'["3", "1"]
matrix tw`i'_12 = tw`i'["2", "1"]
mata: st_matrix("tw`i'_1", st_matrix("tw`i'_12") :/ st_matrix("tw`i'_11"))
matrix tw`i'_2 = tw`i'["2", "2"]
}
forval i = 5/10 {
matrix tw`i' = (tw`i'_1 \ tw`i'_2)
matrix rownames tw`i' = "% ATTs with negative weights" "Sum of negative weights"
matrix colnames tw`i' = "`i'th-Grade"
}
matrix tw_all = (tw5,tw6,tw7,tw8,tw9,tw10)
esttab m(tw_all, fmt(%5.3f)) using "${output}\Table2b.doc", replace nomti

* de Chaisemartin and d'Haultfoeuille’s DIDM Estimator
forval i = 5/10 {
preserve
did_multiplegt chg_enrolment`i' school_gender year t_machine_installation if balancedpanel`i'==1, cluster(schcd) breps(300) ///
placebo(2) ///
covariances jointtestplacebo ///
trends_nonparam(blockcode) trends_lin(school_gender) seed(1234) ///
controls($yicontrols)
mat r`i' = (e(effect_0) \ e(se_effect_0) \ e(N_effect_0))
matrix colnames r`i' = "`i'th-Grade"
restore
}
matrix r_all = (r5,r6,r7,r8,r9,r10)
mat rownames r_all = "b" "se" "N"
esttab m(r_all, fmt(%10.3f)) using "${output}\Table2c.doc", replace nomti

********************************************************************************
*                                   Table 3                                    *
********************************************************************************
use "${user}\data\data.dta", clear
reghdfe chg_enrolment7 aft $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year villageyear) vce(cluster schcd)
outreg2 using "${output}\Table3.doc", replace nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, N, Village x year fixed effects, Y, School x year fixed effects, N, No. of treated schools, 400, No. of control schools, 2566 )
tabschool

use "${user}\data\data_32.dta", clear
reghdfe chg_enrolment7 aft $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year villageyear) vce(cluster schcd)
outreg2 using "${output}\Table3.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, N, Village x year fixed effects, Y, School x year fixed effects, N, No. of treated schools, 400, No. of control schools, 2632 )
tabschool

use "${user}\data\data_33.dta", clear
reghdfe chg_enrolment_grade aft $yearinteracted if (grade<=3 | grade==7) & gender==2 & balancedpanel==1, absorb(school_gender_grade##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table3.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Village x year fixed effects, N, School x year fixed effects, N, No. of treated schools, 482, No. of control schools, - )
preserve
keep if e(sample)
duplicates drop schcd grade, force
tab t_machine_installed grade
restore

reghdfe chg_enrolment_grade aft $yearinteracted if (grade<=5 | grade==7) & gender==2 & balancedpanel==1, absorb(school_gender_grade##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table3.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Village x year fixed effects, N, School x year fixed effects, N, No. of treated schools, 494, No. of control schools, - )
preserve
keep if e(sample)
duplicates drop schcd grade, force
tab t_machine_installed grade if grade==7
restore

reghdfe chg_enrolment_grade aft $yearinteracted if (grade<=5 | (grade==7 & gender==2)) & balancedpanel==1, absorb(school_gender_grade##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table3.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Village x year fixed effects, N, School x year fixed effects, N, No. of treated schools, 494, No. of control schools, - )
preserve
keep if e(sample)
duplicates drop schcd grade gender, force
tab t_machine_installed gender if grade==7
restore

reghdfe chg_enrolment_grade aft if (grade<=5 | (grade==7 & gender==2)) & balancedpanel==1, absorb(school_gender_grade##c.year school_year) vce(cluster schcd)
outreg2 using "${output}\Table3.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, N, Village x year fixed effects, N, School x year fixed effects, Y, No. of treated schools, 491, No. of control schools, - )
preserve
keep if e(sample)
duplicates drop schcd grade gender, force
tab t_machine_installed gender if grade==7
restore

********************************************************************************
*                                   Table 4                                    *
********************************************************************************
use "${user}\data\data.dta", clear

merge m:1 gender schcd year using  "${user}\data\enrolment_adjusted2.dta", keepusing(adjusted2chg_*) nogen

reghdfe adjusted2chg_enrolment7 aft $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table4.doc", replace nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, Time varying school characteristics, N, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Block x Sch. Cat x year fixed effects, N, No. of treated schools, 494, No. of control schools, 2920 )
tabschool

egen block_schcat_year=group(blockcode schcat year)
reghdfe chg_enrolment7 aft $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year block_schcat_year) vce(cluster schcd)
outreg2 using "${output}\Table4.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, Time varying school characteristics, N, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, N, Block x Sch. Cat x year fixed effects, Y, No. of treated schools, 494, No. of control schools, 2873 )
tabschool

merge m:1 villagecode using "${user}\data\village_schoolcat2.dta", keepusing(grade8) nogen

reghdfe chg_enrolment7 aft $yearinteracted if balancedpanel7==1 & grade8==1, absorb(school_gender blockyear) vce(cluster schcd)
outreg2 using "${output}\Table4.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, Time varying school characteristics, N, School fixed effects, Y, School-specific linear time trends, N, Block x year fixed effects, Y, Block x Sch. Cat x year fixed effects, N, No. of treated schools, 64, No. of control schools, 182 )
tabschool

gen she_toilet_year=shetoiletwomenfriendlytoiletinst
reghdfe chg_enrolment7 aft $yearinteracted if balancedpanel7==1 & (she_toilet_year==. | she_toilet_year<2013), absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table4.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, Time varying school characteristics, N, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Block x Sch. Cat x year fixed effects, N, No. of treated schools, 237, No. of control schools, 2795 )
tabschool

gen toilet_treat=toiletg if t_machine_installed==1 & year==t_machine_year
egen maxtoilet_treat=max(toilet_treat), by(schcd)
gen diff=1 if toiletg!=maxtoilet_treat & year>=t_machine_year & t_machine_installed==1
egen todrop=max(diff), by(schcd)
reghdfe chg_enrolment7 aft $yearinteracted if  balancedpanel7==1 & todrop!=1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table4.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, Y, Time varying school characteristics, N, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Block x Sch. Cat x year fixed effects, N, No. of treated schools, 383, No. of control schools, 2920 )
tabschool

global tvcontrols "total_enrolbg bookinlib toiletd toiletb toiletg clrooms clgood smc smcsdp medchk electric library playground ramps cal access water_hp water_well water_tap water_others bld_govt bld_uc bld_dilap wall_pucca wall_wire wall_hedges wall_na"
reghdfe chg_enrolment7 aft $tvcontrols if  balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table4.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School characteristics x year controls, N, Time varying school characteristics, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y, Block x Sch. Cat x year fixed effects, N, No. of treated schools, 494, No. of control schools, 2920 )
tabschool

********************************************************************************
*                                   Table 5                                    *
********************************************************************************

use "${user}\data\data.dta", clear

* gen dummy variables
gen gtoiletratio=c7_2013/toiletg_2013
replace gtoiletratio=0 if toiletg_2013==0
summ gtoiletratio if year==2013 & balancedpanel7==1
gen gtoilet_ratio=gtoiletratio>=7.772192

gen gtoiletfratio=c7_2013/toiletg_func_2013
replace gtoiletfratio=0 if toiletg_func_2013==0
summ gtoiletfratio if year==2013 & balancedpanel7==1
gen gtoiletf_ratio=gtoiletfratio>=8.539367

gen btoiletf=toiletb_func_2013>0
gen btoilet=toiletb_2013>0
gen gtoiletf=toiletg_func_2013>0
gen gtoilet=toiletg_2013>0

* gen interactions
gen aft_gtoilet=aft*(toiletg_2013>0)
gen aft_ngtoilet=aft*(toiletg_2013==0)
gen aft_gtoiletf=aft*(toiletg_func_2013>0)
gen aft_ngtoiletf=aft*(toiletg_func_2013==0)

gen aft_btoilet=aft*(toiletb_2013>0)
gen aft_nbtoilet=aft*(toiletb_2013==0)
gen aft_btoiletf=aft*(toiletb_func_2013>0)
gen aft_nbtoiletf=aft*(toiletb_func_2013==0)

foreach v in gtoilet_ratio gtoiletf_ratio {
gen aft_`v'=aft*(`v'==1)
gen aft_n`v'=aft*(`v'==0)
}

* label variables
foreach v in gtoilet gtoiletf btoilet btoiletf gtoilet_ratio gtoiletf_ratio {
lab var aft_`v' "AfterT x [Indicator=1]"
lab var aft_n`v' "AfterT x [Indicator=0]"
}

reghdfe chg_enrolment7 aft_gtoilet aft_ngtoilet $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table5.doc", replace nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y )
test aft_gtoilet=aft_ngtoilet
tab gtoilet t_machine_installed if year==2013 & e(sample)

reghdfe chg_enrolment7 aft_gtoiletf aft_ngtoiletf $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table5.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y )
test aft_gtoiletf=aft_ngtoiletf
tab gtoiletf t_machine_installed if year==2013 & e(sample)

reghdfe chg_enrolment7 aft_btoilet aft_nbtoilet $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table5.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y )
test aft_btoilet=aft_nbtoilet
tab btoilet t_machine_installed if year==2013 & e(sample)

reghdfe chg_enrolment7 aft_btoiletf aft_nbtoiletf $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table5.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y )
test aft_btoiletf=aft_nbtoilet
tab btoiletf t_machine_installed if year==2013 & e(sample)

reghdfe chg_enrolment7 aft_gtoilet_ratio aft_ngtoilet_ratio $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table5.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y )
test aft_gtoilet=aft_ngtoilet
tab gtoilet_ratio t_machine_installed if year==2013 & e(sample)

reghdfe chg_enrolment7 aft_gtoiletf_ratio aft_ngtoiletf_ratio $yearinteracted if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table5.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y )
test aft_gtoiletf_ratio=aft_ngtoiletf_ratio
tab gtoiletf_ratio t_machine_installed if year==2013 & e(sample)

********************************************************************************
*                                   Table 6                                    *
********************************************************************************

use "${user}\data\data_6.dta", clear

reghdfe a7 aft if balancedpanel7==1, absorb(school_gender##c.year school_year) vce(cluster schcd)
outreg2 using "${output}\Table6.doc", replace nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School x Gender fixed effects, Y, School x Gender specific linear time trends, Y, School x year fixed effects, Y, Block x year fixed effects, N)
tabschool

reghdfe a7 aft if balancedpanel7==1, absorb(school_gender school_year) vce(cluster schcd)
outreg2 using "${output}\Table6.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School x Gender fixed effects, Y, School x Gender specific linear time trends, N, School x year fixed effects, Y, Block x year fixed effects, N)
tabschool

reghdfe a7 aft if balancedpanel7==1, absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table6.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft) addtext(School x Gender fixed effects, Y, School x Gender specific linear time trends, Y, School x year fixed effects, N, Block x year fixed effects, Y)
tabschool

********************************************************************************
*                                   Table 7                                    *
********************************************************************************

use "${user}\data\data.dta", clear

preserve
local v "christian"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", replace nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample) 
restore

preserve
local v "rural"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
local v "public"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
use "${user}\data\data_74.dta", clear
local v "lowcaste"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
gen gonly = mix==0
local v "gonly"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
gen bratio_2013=(total_enrolbg_2013-total_enrol_2013)/total_enrolbg_2013
summ bratio_2013 if year==2013 & balancedpanel7==1
gen malestudent=bratio_2013>=r(mean) & !missing(bratio_2013)
local v "malestudent"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
gen ftchshare=tch_female/(tch_female+tch_male+tch_nr) if year==2013
egen ftchshare2013=max(ftchshare), by(schcd)
summ ftchshare2013 if year==2013 & balancedpanel7==1
gen largeftch=ftchshare2013>=r(mean)
local v "largeftch"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
summ total_enrolbg_2013 if year==2013 & balancedpanel7==1
gen largeschool=total_enrolbg_2013>=r(mean)
local v "largeschool"
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

preserve
summ c7_2013 if year==2013 & balancedpanel7==1
gen largeschoolc7=c7_2013>=r(mean)
gen aft1 = aft*`v'
gen aft_n=aft*(`v'==0)
lab var aft1 "AfterT x [Indicator=1]"
lab var aft_n "AfterT x [Indicator=0]"
reghdfe chg_enrolment7 aft1 aft_n $yearinteracted if balancedpanel7==1 , absorb(school_gender##c.year blockyear) vce(cluster schcd)
outreg2 using "${output}\Table7.doc", append nocons nonotes label bdec(3) sdec(3) ctitle(7th-Grade) keep(aft*) addtext(School characteristics x year controls, Y, School fixed effects, Y, School-specific linear time trends, Y, Block x year fixed effects, Y) 
test aft1 = aft_n
tab `v' t_machine_installed if year==2013 & e(sample)
restore

